package com.yuan.zs.ui.notice;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuan.base.framework.BaseFrameworkActivity;
import com.yuan.base.framework.image.BaseImageLoad;
import com.yuan.base.utils.DateUtil;
import com.yuan.base.utils.DisplayUtil;
import com.yuan.zs.R;
import com.yuan.zs.bean.Notice;

/**
 * 通告详情
 */
public class NoticeDetailActivity extends BaseFrameworkActivity {

	// --------------------------控件--------------------------
	private TextView tv_notice_title;
	private TextView tv_notice_publish_time;
	private TextView tv_notice_publisher;
	private TextView tv_notice_content;
	private LinearLayout ll_img_contain;
	// --------------------------变量--------------------------
	private Notice notice;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_notice_detail;
	}

	@Override
	protected void bindViews() {
		tv_notice_title = findViewById(R.id.tv_notice_title);
		tv_notice_publish_time = findViewById(R.id.tv_notice_publish_time);
		tv_notice_publisher = findViewById(R.id.tv_notice_publisher);
		tv_notice_content = findViewById(R.id.tv_notice_content);
		ll_img_contain = findViewById(R.id.ll_img_contain);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		notice = getIntent().getParcelableExtra("notice");
		if (notice == null) {
			showToast("发生错误");
			closeSelf();
			return;
		}
		init();
	}

	private void init() {
		tv_notice_title.setText(notice.getTitle());
		tv_notice_publish_time.setText(DateUtil.dateToString(notice.getPublishDate()).substring(0, 16));
		tv_notice_publisher.setText(notice.getPublisher());
		tv_notice_content.setText(notice.getContent());
		String[] picList = notice.getPicsList();
		if (picList != null) {
			for (String aPicList : picList) {
				// 手动创建图片视图
				ImageView imageView = new ImageView(this);
				imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
				imageView.setAdjustViewBounds(true);
				LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
				layoutParams.topMargin = DisplayUtil.dp2px(this, 10);
				imageView.setLayoutParams(layoutParams);
				ll_img_contain.addView(imageView);
				BaseImageLoad.load(aPicList, imageView);
			}
		}

	}

}

